var west_tab = true;
$(function() {
	// $('#main').css({'height' :
	// $('.layout-panel-center>.layout-body').height() - $('#menu').height()});
	// $('#main>div').css({'padding-top' : $('#main').height() * 0.4});
	$('.layout-panel-west .nav > li > a')
		.click(
			function() {
				$('.layout-panel-west .nav > li.active').removeClass(
					'active');
				$(this).parent().addClass('active');
				var url = $(this).attr('rel');
				makeFrame(url);
				var menu = $('#menu>.breadcrumb');
				var mtxt = '<li><a href="index.html">首页</a></li>';
				mtxt += '<li id="mli0">' + '<a onclick="lastTabs(0)" href="javascript:void(0);" rel="' + url + '">' + $(this).children('.pp').html() + '</a></li>';
				menu.html(mtxt);
				$('#menu-title').html($(this).children('.pp').html());
				return false;
			});
})

function editPassword() {
	var dialog = parent.$.modalDialog({
		title: '密码修改',
		width: 500,
		height: 250,
		href: 'html/sys/self_edit_password.html',
		buttons: [{
			text: '提交',
			handler: function() {
				// var f = parent.$.modalDialog.handler.find('#form');
				// f.submit();
				parent.$.messager.progress({
					title: '提示',
					text: '数据保存中，请稍后....'
				});
				setTimeout(function() {
					parent.$.messager.progress('close');
					parent.$.messager.show({
						title: '提示',
						msg: '修改密码已成功!',
						timeout: 3000
					});
					parent.$.modalDialog.handler.dialog('close');
				}, 1200);
			}
		}, {
			text: '关闭',
			handler: function() {
				parent.$.modalDialog.handler.dialog('close');
			}
		}]
	});
}

function logout() {
	$.messager.confirm('退出提示', '你确定要退出当前系统吗?', function(r) {
		if (r) {
			location.href = 'login.html';
		}
	});
}

function lastTabs(e) {
	$('#menu-title').html($('#mli' + e + '>a').html());
	$('#mli' + e).nextAll().remove();
	var url = $('#mli' + e + '>a').attr('rel');
	makeFrame(url);
	return false;
}

function openTabs(url, title, e) {
	$('#menu-title', parent.document).html(title);
	var mtxt = '<li id="mli' + e + '"><a onclick="lastTabs(' + e + ')" href="javascript:void(0);" rel="' + url + '">' + title + '</a></li>';
	$('.breadcrumb', parent.document).append(mtxt);
	makeFrame(url);
	return false;
}

function removeTabs() {
	$('.breadcrumb li:last-child', parent.document).remove();
	$('#menu-title', parent.document).html(
		$('.breadcrumb li:last-child>a', parent.document).html());
	var url = $('.breadcrumb li:last-child>a', parent.document).attr('rel');
	makeFrame(url);
	return false;
}

function makeFrame(url) {
	var i = $('#main>iframe', parent.document).attr('src');
	if (url != i) {
		var iframe = '<iframe src="' + url + '">您的浏览器不支持嵌入式框架，或者当前配置为不显示嵌入式框架。</iframe>';
		$('#main', parent.document).html(iframe);
	} else {
		if (west_tab) {
			west_tab = false;
			$('#main>iframe', parent.document).attr('src', url);
			setTimeout(function() {
				west_tab = true;
			}, 1000);
		}
	}
}